﻿using System;
using System.Security.Cryptography;
using Tss.MagicWeb.Kernel.Extension;

namespace Tss.MagicWeb.Kernel.Utility
{
    public static class HashEngine
    {
        private static readonly HashAlgorithm Algorithm = SHA256.Create();

        public static string GenerateHash(string information, string salt)
        {
            byte[] buffer1 = Convert.FromBase64String(salt);
            byte[] buffer2 = buffer1.MergeByteArrays(information.ToByteArray());
            byte[] buffer3 = Algorithm.ComputeHash(buffer2);
            return Convert.ToBase64String(buffer3);
        }

        public static string GenerateSalt()
        {
            var buffer = new byte[0x10];
            RandomNumberGenerator.Create().GetBytes(buffer);
            return Convert.ToBase64String(buffer);
        }

        public static String GenerateSalt(String salt)
        {
            return Convert.ToBase64String(salt.ToByteArray());
        }
    }
}
